import type { PipelineStage } from 'mongoose';

// 联表查询用户
export const joinTableQueryUser = (field: string) => {
  return {
    $lookup: {
      from: 'users',
      as: field,
      localField: field,
      foreignField: '_id',
      pipeline: [{
        $project: {
          password: 0
        }
      }]
    }
  } as PipelineStage;
}

// 联表查询图片
export const joinTableQueryImage = (field: string, pipelines: any[] = []) => {
  return {
    $lookup: {
      from: 'images',
      localField: field,
      foreignField: '_id',
      as: field,
      pipeline: [
        ...pipelines,
        {
          $project: {
            creator: 0,
            status: 0
          }
        }
      ]
    }
  } as PipelineStage;
}

type A = PipelineStage[]